/*
 * 版权信息 : @ 聚均科技
 */
package cn.xiaoke.damowang_boot_test.controller;


import cn.xiaoke.damowang_boot_test.entity.LuckUser;
import cn.xiaoke.damowang_boot_test.service.ILuckUserService;
import cn.xiaoke.damowang_boot_test.util.auto_wrapper.AutoWrapperUtil;
import cn.xiaoke.damowang_boot_test.util.auto_wrapper.TestMain;
import cn.xiaoke.damowang_boot_test.util.auto_wrapper.Where;
import cn.xiaoke.damowang_boot_test.util.auto_wrapper.Wheres;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @author xiaokedamowang
 * @version 1.0
 * @date 2022/2/16 10:39
 */
@RestController
@RequestMapping("/lucky-user")
@RequiredArgsConstructor
public class LuckUserController {

    private final ILuckUserService luckUserService;

    @GetMapping("selectList")
    public Object list() throws Throwable {
        final TestDto testDto = new TestDto();
        testDto.setPhone("1767311");
        testDto.setNum(1).setIndex(123).setCreateEndTime(LocalDateTime.now())
                .setCreateStartTime(LocalDateTime.now().minusDays(1)).setValue("val")
                .setVips(Arrays.asList(4, 5, 6));

//        final LambdaQueryWrapper<LuckUser> lambdaQuery = Wrappers.lambdaQuery();
//        lambdaQuery
//                .or(inner -> {
//                    inner.eq(StringUtils.isNotBlank(testDto.getValue()), LuckUser::getName, testDto.getValue());
//                }).like(StringUtils.isNotBlank(testDto.getPhone()), LuckUser::getPhone, testDto.getPhone());


        final List<LuckUser> list1 = luckUserService.list(TestMain.createLambdaWrapper(LuckUser.class, testDto));
//        final List<LuckUser> list1 = luckUserService.list(lambdaQuery);
//        System.out.println("======================================");
//        return luckUserService.list(AutoWrapperUtil.createWrapper(LuckUser.class, testDto));
        return null;
    }

    public static void main(String[] args) {
        System.out.println(String.format("{%s}", 0));
        final TestDto testDto = new TestDto();
        testDto.setPhone("1767311");
        testDto.setNum(1).setIndex(123).setCreateEndTime(LocalDateTime.now())
                .setCreateStartTime(LocalDateTime.now().minusDays(1)).setValue("val")
                .setVips(Arrays.asList(4, 5, 6));
        final Wrapper<TestDto> wrapper = AutoWrapperUtil.createWrapper(TestDto.class, testDto);
        System.out.println(wrapper);


    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    @Accessors(chain = true)
    public static class TestDto extends TestDto2 {
        @Wheres(value = {
                @Where
        })
        private String phone;
        private Integer current;
        private Integer pageSize;
    }

    @Data
    @Accessors(chain = true)
    public static class TestDto2 {

        @Wheres(value = {
                @Where(column = "name", value = "like"),
                @Where(column = "card", value = "like", join = true),
                @Where(column = "age", value = "like")
        })
        private String value;

        private Integer index;

        @Wheres(value = {
                @Where(column = "vipLevel", value = ">"),
                @Where(column = "age", value = ">="),
                @Where(column = "card", value = "=")
        }, outerJoin = true)
        private Integer num;

        //        @Wheres(value = {
//                @Where(column = "vipLevel")
//        }, outerJoin = true)
//        @Where(column = "vipLevel", value = "in")
        private List<Integer> vips;

        @Wheres(group = "date", value = {
//                @Where(column = "create_time", value = "<="),
                @Where(column = "updateTime", value = "<=")
        },outerJoin = true, innerJoin = true)
        private LocalDateTime createStartTime;

//        @Wheres(group = "date", value = {
//                @Where(column = "create_time", value = ">=", join = false),
//                @Where(column = "updateTime", value = ">=", join = true)
//        }, outerJoin = false, innerJoin = false)
        private LocalDateTime createEndTime;

    }


}
